package com.itheima.ydd.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.SysConfig;
import com.itheima.ydd.mapper.SysConfigMapper;
import com.itheima.ydd.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@Service
@Slf4j
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
    /*@Override
    public ResultData getAll() {

        // 获取所有配置列表
        QueryWrapper<SysConfig> query = new QueryWrapper<>();
        query.orderByAsc("sort_num");
        List<SysConfig> allData = sysConfigMapper.selectList(query);

        // 获取基础配置tab
        List<ConfigTab> configTabs = new ArrayList<>();

        configTabs.add(new ConfigTab("基础配置", "base", null));
        configTabs.add(new ConfigTab("系统配置", "system", null));
        configTabs.add(new ConfigTab("其他配置", "custom", null));

        // 获取tab下children
        for (ConfigTab configTab : configTabs) {
            List<TabOption> children = new ArrayList<>();
            for (SysConfig allConfig : allData) {
                // 如果相等 key
                if (configTab.getKey().equals(allConfig.getTabValue())) {
                    TabOption tabOption = new TabOption(allConfig.getGroupValue(), null);
                    // 设置tab children
                    if (!children.contains(tabOption)){
                        children.add(tabOption);
                    }
                }
            }
            configTab.setChildren(children);
        }
        // 添加children 数据
        for (ConfigTab configTab : configTabs) {
            List<TabOption> children = configTab.getChildren();
            for (TabOption child : children) {
                List<SysConfig> sysConfigs = new ArrayList<>();
                for (SysConfig allDatum : allData) {
                    if(allDatum.getGroupValue().equals(child.getName())){
                        sysConfigs.add(allDatum);
                    }
                }
                child.setData(sysConfigs);
            }
        }


        // configRules + configForm
        ConcurrentHashMap<String, String> configRules = new ConcurrentHashMap<>();
        ConcurrentHashMap<String, String> configForm = new ConcurrentHashMap<>();
        for (SysConfig allDatum : allData) {
            if(EmptyUtils.isNotEmpty(allDatum.getValidator())){
                configRules.put(allDatum.getAttrKey(),allDatum.getValidator());
            }
            if(EmptyUtils.isNotEmpty(allDatum.getAttrKey())){
                configForm.put(allDatum.getAttrKey(),allDatum.getAttrValue());
            }
        }



        ConcurrentHashMap<String, Object> stringObjectHashMap = new ConcurrentHashMap<String, Object>();

        stringObjectHashMap.put("list",configTabs);
        stringObjectHashMap.put("allData",allData);
        stringObjectHashMap.put("configRules",configRules);
        stringObjectHashMap.put("configForm",configForm);


        return ApiResult.success(stringObjectHashMap);

    }
*/

    /**
     * @description: 获取所有配置信息
     * @author: 黄伟兴
     * @date: 2022/9/8 11:21
     * @param: []
     * @return: com.itheima.ydd.common.ResultData
     **/
    @Override
    public ResultData getAll() {

        //1.设置配置信息
        ArrayList   children    = new ArrayList();
        HashMap map00     =new HashMap();
        map00.put("name","站点配置1");
        map00.put("data",list());
        children.add(map00);


        HashMap<String, Object> map0 = new HashMap<>();
        map0.put("name", "基础配置1");
        map0.put("key", "base");
        map0.put("children",children);
        ArrayList list0 = new ArrayList();
        list0.add(map0);




        //2.设置configForm
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("system_name", "优点达资讯系统");
        map1.put("system_logo", "static/admin/image/logo.png");
        map1.put("web_ico", "static/admin/image/favicon.ico");
        map1.put("site_name", "优点达资讯-发现有意思的事儿");
        map1.put("site_link", "http://122.51.249.55:8060/home");
        map1.put("site_keywords", "优点达资讯系统，优点达资讯系统优点达资讯系统优点达资讯系统");
        map1.put("close_website", "2");
        map1.put("copy_code", "皖-备88888888");
        map1.put("copy_info", "优点达版权所有，翻版必究");
        map1.put("phone", "hewu1122@163.com");
        map1.put("copy_url", "http://www.baidu.com");
        map1.put("black_ip", "");
        map1.put("login_title", "优点达资讯系统");
        map1.put("login_bg", "static/admin/image/loginbg.png");
        map1.put("notic_title", "感谢广告网网友");
        map1.put("web_img", "upload/images/20211101/1635766045081.jpg");
        map1.put("notic_content", "\"非常感谢广告网网友对本网站的关注和喜爱，如果有任何的问题，欢迎提供宝贵意见，练习方式参见网站底部邮箱。");
        ArrayList<Object> list2 = new ArrayList<>();
        list2.add(map1);

        //3.设置configRules
        HashMap<String, Object> map2 = new HashMap<>();
        map2.put("site_name", "[{\"required\":true,\"message\":\"站点名必须\",\"trigger\":\"blur\"}]");
        ArrayList<Object> list3 = new ArrayList<>();
        list3.add(map2);


        //4.设置allData数据
        HashMap<String, Object> map3 = new HashMap<>();
        map3.put("id", 100);
        map3.put("attr_key", "attr_key");
        map3.put("attr_value", "attr_value");
        map3.put("validator", "validator");
        map3.put("config_value", null);
        map3.put("type", 1);
        ArrayList<Object> list4 = new ArrayList<>();
        list4.add(map3);



        HashMap<String, Object> map = new HashMap<>();
        map.put("list", list0);
        map.put("configForm", map1);
        map.put("configRules", map2);
        map.put("allData", list4);


        System.out.println(map);

        return ResultData.ok(map);
    }


}
